import { defineStore } from "pinia";
import livesApi from "@/api/live";
// import type {
//   CategoryItemListData1,
//   CategoryListData2,
//   CurrentCategoryData,
// } from "@/api/live";
import { ElMessage } from "element-plus";

type LiveStoreStateData = {
  // categoryItemList: CategoryItemListData1,//大的商品分类
  // categoryList: CategoryListData2, //与首页navList对应的分类列表
  // currentCategory: CurrentCategoryData //轮播图
};

export const useLivesStore = defineStore("live", {
  state: (): any => {
    return {
      categoryId: 1005000,
      categoryItemList: [], //大的商品分类
      categoryList: [], //与首页navList对应的分类列表
      currentCategory: [], //轮播图
    };
  },
  actions: {
    // 居家生活页
    async getLives() {
      try {
        const result = await livesApi.getLives(this.categoryId);
        this.categoryItemList = result.categoryItemList;
        this.categoryList = result.categoryList;
        this.currentCategory = result.currentCategory;

      } catch (error) {
        ElMessage.error("获取数据失败");
      }
    },
  },
  getters: {
    //   nav分类
    category(state) {
      return state.categoryList || [];
    },
    // 轮播图
    bannerList(state) {
      return (state.currentCategory || {}).bannerList || [];
    },
    // 主体内容 
    categoryMain(state) {
      return state.categoryItemList.map((item: any) => {
        return item;
      });
    },
    itemLists(state) {
      return state.categoryItemList.map((item: any) => {
        return item.itemList;
      });
    },
  },
});
